package cn.arvin.umeditor.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.arvin.umeditor.util.UEditorUploader;

/**
 * Created by Arvin.Z on 2017/3/3.
 */
@Controller
public class UEditorController {

    @RequestMapping("/index")
    public String index() {
        return "index";
    }

    /**
     * UEditor上传图片
     * @author Arvin.Z
     * @date 2017年3月3日 下午4:35:27
     */
    @RequestMapping("/doupload_image")
    @ResponseBody
    public String doUploadImage(@RequestParam(required = false) String callback, HttpServletRequest request) throws Exception {
        UEditorUploader uploader = new UEditorUploader(request);
        uploader.setAllowFiles(new String[] { ".gif" , ".png" , ".jpg" , ".jpeg" , ".bmp" });
        uploader.setSavePath("/upload/umeditor_upload");
        uploader.setMaxSize(1024);
        uploader.upload();
        String result = uploader.getJsonResult(callback);
        System.out.println("result = " + result);
        return result;
    }

}
